package com.hai.comtroller;

import com.hai.bean.Mixed;
import com.hai.bean.Response;
import com.hai.bean.User;
import com.hai.bean.YesNo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 黄海 on 2/11/2017.
 */
@RestController
@RequestMapping(value = "/tj/")
public class TjController {
    @RequestMapping(value = "getString")
    public Response getString(String p) {
        if (YesNo.Y.toString().equalsIgnoreCase(p))
            return new Response<String>(Response.CODE_SUCCESS, "success");
        else return new Response<String>("failed", Response.CODE_FAILED);
    }
    @RequestMapping(value = "getMixedNull")
    public Response<Mixed> getMixedNull(String p) {
        if (YesNo.Y.toString().equalsIgnoreCase(p))
            return new Response<Mixed>(Response.CODE_SUCCESS, new Mixed());
        else return new Response<Mixed>("failed", Response.CODE_FAILED);
    }
    @RequestMapping(value = "getUser")
    public Response<User> getUser(String p) {
        if (YesNo.Y.toString().equalsIgnoreCase(p))
            return new Response<User>(Response.CODE_SUCCESS, new User("hai","123456"));
        else return new Response<User>("failed", Response.CODE_FAILED);
    }

    @RequestMapping(value = "getUserList")
    public Response<List<User>> getUserList(String p) {
        if (YesNo.Y.toString().equalsIgnoreCase(p)){
            List<User> list = new ArrayList<>();
            for (int i = 0; i < 3; i++) {
                list.add(new User("name" + i, "password" + i));
            }
            return new Response<List<User>>(Response.CODE_SUCCESS, list);
        }
        else return new Response<List<User>>("failed", Response.CODE_FAILED);
    }
}
